package eproject.mm.com.projectsupervision.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import eproject.mm.com.projectsupervision.R;
import eproject.mm.com.projectsupervision.widget.IconFontTextview;

/**
 * Created by momotea on 2018/3/15.
 */

public class DataAdapter extends BaseAdapter {
    private List<Map> list;
    private Context context;
    private LayoutInflater inflater;

    public DataAdapter(Context context, List list){
        this.list = list;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Map getItem(int position) {
        return list.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        final Map item = getItem(position);

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.data_item, null);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            //holder.iftv_icon = (IconFontTextview) convertView.findViewById(R.id.iftv_icon);

            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_title.setText((String)item.get("describes"));
        holder.tv_time.setText((String)item.get("createtime"));

        return convertView;
    }

    private static class ViewHolder {
        TextView tv_title;
        TextView tv_time;
        IconFontTextview iftv_icon;
    }

    public void removeAt(int pos){
        list.remove(list.get(pos));
    }
}
